﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace super_scrable.Models
{
    public class Letter : IComparable
    {
        public static List<Letter> letters = new List<Letter>(new Letter[] {new Letter(1, 'a'), new Letter(3, 'b'), new Letter(3, 'c'), new Letter(2, 'd'), new Letter(1, 'e'), new Letter(4, 'f'), new Letter(2, 'g'), new Letter(4, 'h'), new Letter(1, 'i'), new Letter(8, 'j'), new Letter(1, 'k'), new Letter(9, 'l'), new Letter(2, 'm'), new Letter(1, 'n'), new Letter(1, 'o'), new Letter(3, 'p'), new Letter(8, 'q'), new Letter(1, 'r'), new Letter(1, 's'), new Letter(1, 't'), new Letter(1, 'u'), new Letter(4, 'v'), new Letter(9, 'w'), new Letter(9, 'x'), new Letter(9, 'y'), new Letter(9, 'z')});

        private int point;

        public int Point
        {
            get { return point; }
            set { point = value; }
        }

        private char character;

        public char Character
        {
            get { return character; }
            set {
                character = Char.ToUpper(value);
            }
        }

        public int CompareTo(Object o)
        {
            if (o == null) return 1;

            Letter l = o as Letter;

            if (this.character == l.character) return 0;
            if (this.character < l.character) return -1;
            return 1;
        }

        public Letter() {
        }

        public Letter(char character) : this()
        {
            this.character = character;
            this.point = getPoint(character);
        }

        public Letter(int point, char character) : this()
        {
            this.point = point;
            this.character = character;
        }

        public static int getPoint(char character)
        {
            int point = 0;

            foreach(Letter l in letters) {
                if (l.character == Char.ToLower(character)) point = l.point;
            }

            return point;
        }

        override public String ToString()
        {
            return Char.ToUpper(character).ToString();
        }
    }
}
